package com.ruoyi.common.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper extends BaseMapper<Category> {

    @Select("SELECT id, title, icon, sort_order, is_active, created_at, updated_at FROM category WHERE is_active = 1 ORDER BY sort_order ASC")
    List<Category> selectAllActive();

    @Insert("INSERT INTO category(title, icon, sort_order, is_active) VALUES(#{title}, #{icon}, #{sortOrder}, #{isActive})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Category category);

    @Update("UPDATE category SET title = #{title}, icon = #{icon}, sort_order = #{sortOrder}, is_active = #{isActive} WHERE id = #{id}")
    int update(Category category);

    @Delete("DELETE FROM category WHERE id = #{id}")
    int deleteById(Integer id);

    @Select("SELECT id, title, icon, sort_order, is_active, created_at, updated_at FROM category WHERE id = #{id}")
    Category selectById(Integer id);
}